package com.ihr360.insurance.controller.staffWeb;

import com.ihr360.commons.exception.Ihr360Exception;
import com.ihr360.commons.vo.PageData;
import com.ihr360.insurance.entity.request.MonthlyLedgerRequest;
import com.ihr360.insurance.model.dto.ledger.MonthlyLedgerSummary;
import com.ihr360.insurance.model.vo.MonthlyLedgerVo;
import com.ihr360.insurance.service.MonthlyLedgerService;
import com.ihr360.insurance.service.MonthlyLedgerSummaryService;
import com.ihr360.rest.service.SimpleRestService;
import com.ihr360.rest.webmvc.AbstractRestSimpleWithLongIdController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Eric on 2018/6/5/005.
 */
@RestController
@RequestMapping("/benefit/staffWeb")
/*@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME,
        subModuleCode = ModuleCodeStore.Module.Benefit.BENEFIT_STAFF_WEB_CODE,
        subModuleName = ModuleCodeStore.Module.Benefit.BENEFIT_STAFF_WEB_NAME,
        isPublic = true, hasExtendsAbstractRestController = true)*/
public class BenefitStaffWebController extends AbstractRestSimpleWithLongIdController<MonthlyLedgerSummary> {

    @Autowired
    private MonthlyLedgerSummaryService monthlyLedgerSummaryService;

    @Autowired
    private MonthlyLedgerService monthlyLedgerService;

    @Autowired
    private MonthlyLedgerSummaryService summaryService;

    @Override
    public SimpleRestService getSimpleRestService() {
        return summaryService;
    }

/*
    @FunctionDefinition(functionName = "审批获取台账的具体数据列表", functionCode = ModuleCodeStore.Function.VIEW, isPublic = true)
*/
    @RequestMapping(value = "/approval/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public PageData<MonthlyLedgerVo> getLedgerApprovalList(@RequestParam String companyId,
                                                           @RequestParam Long summaryId,
                                                           @RequestBody MonthlyLedgerRequest req) {
        MonthlyLedgerSummary summary = monthlyLedgerSummaryService.getOne(summaryId);
        if (summary == null) {
            throw new Ihr360Exception(null, "社保台账不存在");
        }
        return monthlyLedgerService.getLedgerList(companyId, summary.getUserId(), req);
    }
}
